<template>
	<view class="oHome o-h">
		<u-navbar class="nav" bgColor="#fff" titleStyle="color:#fff;font-size:28rpx;" :placeholder="true">
			<!-- <view class="f-c u-nav-slot" slot="left">
				<view class="tabs dfa f16">
					<view  class="tab tac f-c-xc" :class="current === index?'isTab':''"
						v-for="(item,index) in tabs" :key="index" :style="{color:current === index?'#000':'#666'}"
						@click="handTab(index)">{{item}}
						<view class="line" :style="{background: current === index?subColor:'#fff'}"></view>
					</view>
				</view>
			</view>
			<view class="f-c u-nav-slot" slot="right">
				<u-icon name="search" color="#000" size="32" @click="sShow = !sShow"></u-icon>
			</view> -->
		</u-navbar>
		<view style="position: fixed;z-index: 99;">
			<view class="search">
				<u-search placeholder="请输入订单号或手机号" v-model="newParams.search_for" shape="square" @change="searchChange"></u-search>
			</view>
			<view class="dfbc bb1 w100 bf">
				<view class="f-g-1">
					<u-tabs class="f-g-1" :list="nList1" :lineColor="subColor" :lineWidth="0" :current="0"
						:activeStyle="{color:'#000',fontWeight:'bold',fontSize:'34rpx'}"
						:inactiveStyle="{fontSize:'34rpx'}" @click="orderType">
					</u-tabs>
				</view>
				<view class="f-g-0 tar flex f-y-c" style="color:#606266;width: 180rpx;">
					<uni-datetime-picker v-model="time" type="date" @change="maskClick">
						<view class="f12 flex">
							<view class="tar f16 iconfont icon-a-13Jtiaojie pr5"></view>
							<view class="">日期</view>
						</view>
					</uni-datetime-picker>
					<uni-datetime-picker v-model="time" type="daterange" @change="maskClick">
						<view class="f12 flex">
							<view>/ 区间</view>
						</view>
					</uni-datetime-picker>
				</view>
			</view>
			<view class="p10 c6 bff1">
				<view class="f-1" style="overflow: auto;">
					<view class="types" style="overflow-x: auto;">
						<view class="type c0 f12" :class="typeNum === index?'isType':''" v-for="(item,index) in list2"
							:key="index"
							:style="{background:typeNum === index?'linear-gradient(to right, #fee14f, #fdc450)':'',fontWeight:typeNum===index?'bold':''}"
							@click="typeChange(index,item)">{{item.name}}
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="scroll f-1 bf8 db">
			<!--简洁 -->
			<view class="f-1 p10 bff1" style="margin-top: 230rpx;">
				<order v-if="acTab==2 || acTab==1" :current="current" :orderList="orderList" @op="op"></order>
				<!-- <storedValue v-else-if="acTab==3" :current="current" :orderList="orderList" @op="svOp"></storedValue>
				<payBill v-else-if="acTab==5" :current="current" :orderList="orderList" @op="payOp"></payBill>
				<instoreOrder v-else-if="acTab==4" :current="current" :orderList="orderList" @op="handOp"
					@storeNotes="storeNotes"></instoreOrder>
				<jfOrder v-else-if="acTab==6" :current="current" :orderList="orderList" @op="jfop"></jfOrder> -->
				<newOrder v-if="acTab==10" :current="current" :orderList="orderList" @newOrder="newOrder"
					:parentParam="newParams"></newOrder>
				<view v-if="orderList.length==0" class="np f-c-c">
					<view class="iconfont icon-queshengtu cb" style="font-size: 90rpx;"></view>
					<view class="f12 cb mt20">暂无订单</view>
				</view>
			</view>
			<!-- <u-popup :show="show" :round="10" @close="show = false" @open="show = true">
				<view class="tac">
					<view class="p15 bb1" @click="finish">批量处理完成</view>
					<view class="p15" @click="draw">批量处理领取</view>
					<view class="bf8"
						style="width:100%; height:18rpx;margin-left: -100rpx;margin-top:-4rpx;z-index:999">
					</view>
					<view class="p15" @click="show = false">取消</view>
				</view>
			</u-popup> -->
		</view>
		<u-modal :show="notesShow" :showCancelButton="true" :negativeTop="30" title="订单备注" cancelText="取消"
			:confirmColor="subColor" @cancel="notesShow=false" @close="notesShow=false" @confirm="notesConfirm">
			<view class="slot-content f-1">
				<u--textarea v-model="reason" placeholder="请输入备注信息"></u--textarea>
			</view>
		</u-modal>
		<u-popup :show="fqps" :safeAreaInsetBottom="false" round="10" @close="fqps=false" @open="fqps=true"
			mode="center">
			<view class="psw">
				<view class="flex p-10-0">
					<view class="f-g-0">配送地址</view>
					<view class="ml10 mr15" v-if="rows.address">
						<view class="wei">
							{{ rows.address.address }} {{ rows.address.description }}
						</view>
						<view class="mt5 f12">
							{{ rows.address.contact }}（{{ rows.address.call }}）{{
					              rows.address.mobile
					            }}
						</view>
					</view>
				</view>
				<view class="flex p-10-0">
					<view class="f-g-0">配送方式</view>
					<view class="ml10 mr15 f-g-1">
						<u-radio-group v-model="psform.deliveryType" @change="changeType" placement="column"
							iconColor="#000" labelSize='14'>
							<view class="mb5" v-if="rows.deliveryStoreRule && rows.deliveryStoreRule.deliveryType==1">
								<u-radio :activeColor="subColor" label="平台配送" :name="1"></u-radio>
							</view>
							<view class="mb5">
								<u-radio :activeColor="subColor" label="门店自配送" :name="2"></u-radio>
							</view>
						</u-radio-group>
					</view>
				</view>
				<view class="flex p-10-0">
					<view class="f-g-0">配送渠道</view>
					<view class="ml10 mr15 f-g-1">
						<u-radio-group v-model="psform.channel" placement="column" labelSize='14' iconColor="#000">
							<view class="mb5" v-if="psform.deliveryType == 2">
								<u-radio :activeColor="subColor" label="门店自配送" :name="0"></u-radio>
							</view>
							<view class="mb5"
								v-if="fhChannel.includes(1) && (rows.deliveryStoreRule && rows.deliveryStoreRule.deliveryType==2 || psform.deliveryType==1)">
								<u-radio :activeColor="subColor" :label="mytName" :name="1"></u-radio>
							</view>
							<view class="mb5"
								v-if="fhChannel.includes(2) && (rows.deliveryStoreRule && rows.deliveryStoreRule.deliveryType==2 || psform.deliveryType==1)">
								<u-radio :activeColor="subColor" :label="mKName" :name="2"></u-radio>
							</view>
							<view class="mb5" v-if="psform.deliveryType == 2 && fhChannel.includes(3)"><u-radio
									:activeColor="subColor" :label="wsbName" :name="3"></u-radio>
							</view>
						</u-radio-group>
					</view>
				</view>
				<view class="mt20 psbt">
					<u-button type="primary" text="确定" :color="subColor" customStyle="color:'#000'"
						@click="save"></u-button>
				</view>
			</view>
		</u-popup>

		<u-modal :show="vipUser" :negativeTop="200" title="会员查询" confirmText="查询" showCancelButton
			:confirmColor="subColor" cancelColor="#000" @confirm="search" @cancel="vipUser = false"
			@close="vipUser = false" :closeOnClickOverlay="true" zoom>
			<view class="slot-content">
				<u--input v-model="phone" type="number" placeholderClass="inni" placeholderStyle="color:#c1c1c1"
					placeholder="请输入手机号" border="none"
					:customStyle="{'width':'100%','flex':1,'background': '#f6f6f6','padding': '10px 15px',}" clearable>
				</u--input>
			</view>
		</u-modal>

		<u-popup :show="showPay" :round="10" @close="showPay=false" @open="showPay=true" :closeOnClickOverlay="true">
			<view class="p15 c0 f16">
				<view class="dfbc mb10">
					<text>支付金额</text>
					<text class="f14 " :style="{color:subColor}">￥{{form.money}}</text>
				</view>
				<view class="dfbc bb1 p-10-0">
					<u-radio-group v-model="pay.payChannel" placement='column' iconPlacement='right'
						@change="changePay">
						<u-radio :activeColor="subColor" name="authCode" :labelSize="18" :iconSize="14"
							:customStyle="{marginBottom: '50rpx'}">付款码支付</u-radio>
						<u-radio :activeColor="subColor" name="balance" :labelSize="18" :iconSize="14"
							:customStyle="{marginBottom: '50rpx'}">
							<!-- <text v-if="payVip && payVip.id">余额支付<text class="f12 c9 ml10"
									:style="{color: subColor}">{{(`余额:${payVip.account.balance}`)}}</text>
									</text>
							<text v-else>余额支付</text> -->
						</u-radio>
						<u-radio :activeColor="subColor" name="cash" :labelSize="18" :iconSize="14"
							:customStyle="{marginBottom: '50rpx'}">现金支付</u-radio>
					</u-radio-group>
				</view>
				<view>
					<u-button text="立即支付" :color="subColor" @click="goPay"
						:disabled="!pay.payChannel || (pay.payChannel == 'authCode' && !pay.authCode || pay.payChannel == 'balance' && !payVip.id)">
					</u-button>
				</view>
			</view>
		</u-popup>
		<dLoading :status="loading"></dLoading>
		<tab-bar></tab-bar>
		<button type="default" open-type="contact" class="weixinButton">
			<image src="https://faquniapp.oss-cn-hangzhou.aliyuncs.com/kefutubiao.png" class="img"></image>
			<view class="text">客服</view>
		</button>
	</view>
</template>

<script>
	import {
		mapState,
	} from 'vuex'
	import order from "./components/order.vue"
	import newOrder from "./components/newOrder.vue"
	import storedValue from "./components/storedValue.vue"
	import payBill from "./components/payBill.vue"
	import instoreOrder from "./components/instoreOrder.vue"
	import jfOrder from "./components/jforder.vue"
	import TabBar from '@/components/common/tabbar.vue'
	export default {
		components: {
			order,
			newOrder,
			storedValue,
			payBill,
			instoreOrder,
			jfOrder,
			TabBar,
		},
		data() {
			return {
				// 新增
				newParams: {
					order_no:'',
					limit: 10,
					status: 0,
					order_status: 0,
					page: 1,
					product_name: '',
					phone:'',
					search_for:''
				},
				eStutas: '',
				subColor: uni.getStorageSync('subject_color'),
				times: 0,
				current: 0,
				typeNum: 0,
				acTab: 2,
				pageUrl: this.api.orderList,
				newPageUrl: this.api.newOrderList,
				// tabs: ['简洁', '售后'],
				tabs: ['订单'],
				list1: [{
					name: '自提订单',
					value: 2,
					badge: {
						value: 0
					},
					role: 'ziti',
				}, {
					name: '外送订单',
					value: 1,
					badge: {
						value: 0
					},
					role: 'waisong',
				}, {
					name: '店内订单',
					value: 4,
					badge: {
						value: 0
					},
					role: 'diannei',
				}, {
					name: '买单订单',
					value: 5,
					badge: {
						value: 0
					},
					role: 'maidan',
				}, {
					name: '储值订单',
					value: 3,
					badge: {
						value: 0
					},
					role: 'chuzhi',
				}, {
					name: '积分商城',
					value: 6,
					badge: {
						value: 0
					},
					role: 'jfsc',
				}],
				nList1: [{
						name: '外卖',
						value: 10,
					},
					// {
					// 	name: '点单',
					// 	value: 1,
					// },
					// {
					// 	name: '融合版订单',
					// 	value: 2,
					// },
				],
				list2: [],
				listzt: [{
						name: '全部',
						value: '',
					},
					// {
					// 	name: '待支付',
					// 	value: 'unpaid',
					// }, {
					// 	name: '待接单',
					// 	value: 'unReceived',
					// }, {
					// 	name: '制作中',
					// 	value: 'making',
					// }, {
					// 	name: '待取单',
					// 	value: 'waiting',
					// }, {
					// 	name: '已完成',
					// 	value: 'complete',
					// }, {
					// 	name: '已关闭',
					// 	value: 'refund',
					// }, {
					// 	name: '已取消',
					// 	value: 'close',
					// },
				],
				listwm: [{
					name: '全部',
					value: '',
				}, {
					name: '待支付',
					value: 'unpaid',
				}, {
					name: '待接单',
					value: 'unReceived',
				}, {
					name: '制作中',
					value: 'making',
				}, {
					name: '待配送',
					value: 'waiting',
				}, {
					name: '配送中',
					value: 'delivery',
				}, {
					name: '已完成',
					value: 'complete',
				}, {
					name: '已关闭',
					value: 'refund',
				}, {
					name: '已取消',
					value: 'close',
				}],
				listcz: [{
					name: '全部',
					value: '',
				}, {
					name: '已完成',
					value: 'complete',
				}],
				listmd: [{
					name: '全部',
					value: '',
				}, {
					name: '已完成',
					value: 'pay',
				}, {
					name: '已关闭',
					value: 'refund',
				}],
				listdmf: [{
					name: '全部',
					value: '',
				}, {
					name: '待支付',
					value: 'unpaid',
				}, {
					name: '待接单',
					value: 'unReceived',
				}, {
					name: '制作中',
					value: 'making',
				}, {
					name: '就餐中',
					value: '1',
				}, {
					name: '待取单',
					value: '2',
				}, {
					name: '已完成',
					value: 'pay',
				}, {
					name: '已取消',
					value: 'close',
				}, {
					name: '已关闭',
					value: 'refund',
				}],
				listdn: [{
					name: '全部',
					value: '',
				}, {
					name: '待接单',
					value: 'unReceived',
				}, {
					name: '制作中',
					value: 'making',
				}, {
					name: '待取单',
					value: 'waiting',
				}, {
					name: '就餐中',
					value: 'dining',
				}, {
					name: '已完成',
					value: 'complete',
				}, {
					name: '已取消',
					value: 'close',
				}, {
					name: '已关闭',
					value: 'refund',
				}],
				listjf: [{
					name: '全部',
					value: '',
				}, {
					name: '待取货',
					value: 'unReceived',
				}, {
					name: '已完成',
					value: 'complete',
				}, {
					name: '已关闭',
					value: 'refund',
				}],
				options_status: {

					'0': {
						value: 0,
						label: '全部',
					},
					'1': {
						value: 1,
						label: '交易完成',
					},
					'10': {
						value: 10,
						label: '订单已创建',
					},
					'20': {
						value: 20,
						label: '已支付',
					},
					'30': {
						value: 30,
						label: '待接单',
					},
					'40': {
						value: 40,
						label: '已接单',
					},
					'50': {
						value: 50,
						label: '备餐中',
					},
					'51': {
						value: 51,
						label: '已出餐',
					},
					'52': {
						value: 52,
						label: '已取餐',
					},
					'101': {
						value: 101,
						label: '交易关闭',
					},
				},
				// 新增
				sjList: [{
						name: '全部',
						value: 0
					}, {
						name: '待退款',
						value: 1
					},
					{
						name: '退款成功',
						value: 2
					},
					{
						name: '退款关闭',
						value: 3
					},
					{
						name: '先囤单',
						value: 4
					},
					{
						name: '后约单',
						value: 5
					},
					{
						name: '团购单',
						value: 6
					},
				],

				time: [],
				start: Date.now() - 1000000000,
				end: Date.now() + 1000000000,
				show: false,
				orderList: [],
				refresherEnabled: true,
				triggered: false,
				queryForm: {
					keyword: "",
					userKeyword: "",
					state: "",
					scene: 2,
					pageNo: 1,
					pageSize: 10,
				},
				notesShow: false,
				reason: '',
				noteForm: {},
				fqps: false,
				psform: {
					deliveryType: 1,
					channel: 1,
				},
				storeInfo: {},
				rows: {},
				mytName: "麦芽田聚合配送",
				mKName: "码科配送",
				wsbName: "外送帮",
				fhChannel: [],
				loading: '',
				form: {},
				vipUser: false,
				phone: '',
				showPay: false,
				pay: {
					payChannel: 0,
					authCode: 0,
					payUserId: 0,

				},
				orderInfo: {},
				status: 'loading',
				sShow: false,
				formInline: {
					order_no: '',
					mobile: '',
					store_name: '',
					product_name: '',
					status: '',
					delivery_status: '',
					delivery_time: '',
					page: 1,
					limit: 10
				}
			}
		},
		computed: {
			...mapState({
				role: state => state.user.roleData || [],
			}),
		},
		onReachBottom() {
			if (this.eStutas.index == 1) {
				uni.showLoading()
				this.queryForm.pageNo++
				this.beg.request({
					url: this.pageUrl,
					method: 'POST',
					data: {
						page: this.queryForm.pageNo,
						limit: this.queryForm.pageSize,
					},
				}).then(res => {
					if (res.code == 1) {
						uni.hideLoading()
						this.orderList = this.orderList.concat(res.data.data)
						res.data.data.forEach((v) => {
							v.status_name = this.options_status[v.status].label;
							if (v.refund != null) {
								v.refund_name = '退款';
							} else {
								v.refund_name = '支付';
							}
						})
					}
				})
			} else {
				uni.showLoading()
				this.newParams.page++
				this.beg.request({
					url: this.newPageUrl,
					method: 'POST',
					data: this.newParams,
				}).then(res => {
					if (res.code == 1) {
						uni.hideLoading()
						res.data.data.map(item => {
							item.user_info = JSON.parse(item.user_info)
							item.total_amount = this.filterMoney(item.total_amount)
							item.image_list = JSON.parse(item.image_list)
						})
						this.status = 'nomore'
						this.orderList = this.orderList.concat(res.data.data)
					}
				})
			}
		},
		onLoad() {
			this.list1.forEach((v, i) => {
				if (!this.role.includes(v.role)) {
					this.list1.splice(i, 1)
				} else {
					this.nList1.push(v)
				}
			})
			if (this.nList1 && this.nList1.length) {
				this.orderType({
					value: this.nList1[0].value
				})
			}
			this._freshing = false;
			this.list2 = this.sjList
			setTimeout(() => {
				this.isload = true
			}, 1000)
		},
		watch: {
			time(newval) {
				console.log('范围选:', this.time);
			}
		},
		onShow() {
			if (this.isload) {
				if (this.acTab == 1) {
					this.fetchData()
				}
				if (this.acTab == 10) {
					// this.newParams.page = 1
					// this.newOrder()
				}

			}
		},
		methods: {
			async orderType(e) {
				this.eStutas = e
				this.loading = true
				this.acTab = e.value
				this.typeNum = 0
				this.queryForm.state = ''
				this.queryForm.startTime = ''
				this.queryForm.endTime = ''
				this.queryForm.timeType = ''
				this.queryForm.pageNo = 1

				this.newParams.page = 1
				this.newParams.product_name = ''
				this.newParams.order_status = 0
				this.newParams.status = 0

				if (e.value == 1) {
					this.list2 = this.listwm
					this.queryForm.scene = 1
					this.pageUrl = this.api.orderList
					this.fetchData()
					// } else if (e.value == 2) {
					// 	this.list2 = this.listzt
					// 	this.queryForm.scene = 2
					// 	this.pageUrl = this.api.orderList
					// } else if (e.value == 3) {
					// 	this.list2 = this.listcz
					// 	this.queryForm.scene = 3
					// 	this.pageUrl = this.api.storedValueOrder
					// } else if (e.value == 5) {
					// 	this.list2 = this.listmd
					// 	this.queryForm.scene = 1
					// 	this.pageUrl = this.api.personPay
					// } else if (e.value == 4) {
					// 	this.list2 = this.listdn
					// 	this.queryForm.scene = 3
					// 	this.pageUrl = this.api.inStoreOrder
					// } else if (e.value == 6) {
					// 	this.list2 = this.listjf
					// 	this.queryForm.scene = 4
					// 	this.pageUrl = this.api.pointsMallOrder
				} else if (e.value == 10) {
					this.list2 = this.sjList
					this.newOrder()
					this.loading = false
				} else if (e.value == 2) {
					this.getFusionList()
				}

				this.loading = false
			},
			typeChange(i, v) {
				if (this.eStutas.index == 1) {
					this.typeNum = i
					this.queryForm.state = v.value
					this.queryForm.pageNo = 1
					this.fetchData()
				} else {
					this.typeNum = i
					this.newParams.status = i
					this.newParams.page = 1
					this.newOrder()
				}

			},
			// 新增
			filterMoney(num) {
				return (num / 100).toFixed(2)
			},
			async newOrder(type) {
				uni.showLoading()
				await this.beg.request({
					url: this.newPageUrl,
					method: 'POST',
					data: this.newParams,
				}).then(res => {
					uni.hideLoading()
					if (res.code == 1) {
						res.data.data.map(item => {
							item.user_info = JSON.parse(item.user_info)
							item.total_amount = this.filterMoney(item.total_amount)
							item.image_list = JSON.parse(item.image_list)
						})
						this.orderList = res.data.data

					}
				})
			},
			// 查询订单列表
			async fetchData(type) {
				this.status = 'loading'
				let {
					data: {
						data,
						pageNo,
						pageSize,
						count
					},
				} = await this.beg.request({
					url: this.pageUrl,
					method: 'POST',
					data: {
						userKeyword: this.queryForm.keyword,
						page: this.queryForm.pageNo,
						limit: this.queryForm.pageSize,
					},
					// data: this.queryForm,
				})
				data.forEach((v) => {
					v.status_name = this.options_status[v.status].label;
					if (v.refund != null) {
						v.refund_name = '退款';
					} else {
						v.refund_name = '支付';
					}
				})

				if (type != 'nextPage' || this.queryForm.pageNo == 1) {
					this.orderList = data
				} else {
					if (data.length == 0) {
						this.status = 'nomore'
						return
					}
					this.orderList = this.orderList.concat(data)
				}
				// this.list1[this.acTab].badge.value = total
				this.status = 'loadmore'
				this.time = ''
				this.loading = false
			},
			// 融合版订单列表
			getFusionList() {
				uni.showLoading()
				this.beg.request({
					url: '/index.php/admin/order.ShopOrder/getList',
					method: 'post',
					data: this.formInline
				}).then(res => {
					uni.hideLoading()
					
				})
			},
			// 点单组件回调方法
			async op(type, v) {
				if (type == 'comDelivery') {
					this.open(v)
					return
				} else if (type == 'call') {
					const {
						msg
					} = await this.beg.request({
						url: `${this.api.call}/${v.takeScreen.id}`,
						method: "POST",
					})
					uni.$u.toast(msg)
					this.fetchData()
					return
				} else if (type == 'refusal') {
					uni.showModal({
						title: '取消订单',
						content: '请谨慎操作，建议提前与客户沟通达成一致！',
						cancelText: '再考虑下',
						confirmText: '确认取消',
						success: async (res) => {
							if (res.confirm) {
								return uni.navigateTo({
									url: `/pages/order/refusal?id=${v.id}&scene=${v.scene}&storeId=${v.storeId}`
								})
							}
						}
					})
					return
				}
				let n = '',
					a = '',
					url = '',
					data = {}
				switch (type) {
					case 'orderPrint':
						n = "你确定打印该订单吗";
						a = 'printOrder';
						break;
					case 'canceling':
						n = "你确定取消订单吗";
						a = 'oClose';
						break;
					case 'refusal':
						n = "你确定拒单吗";
						a = 'refund';
						url = '/admin/order.Place/pendOrder';
						data = {
							order_id: v.id,
							confirm_result: 2
						};
						break;
					case 'receiving':
						n = "你确定立即接单吗";
						a = 'received';
						url = '/admin/order.Place/pendOrder';
						data = {
							order_id: v.id,
							confirm_result: 1
						};
						break;
					case 'refunding':
						n = "你确定同意退款吗";
						a = 'refund';
						break
					case 'refundOrder':
						n = "你确定退款吗";
						a = 'refund';
						url = '/admin/order.Place/refundOrder';
						data = {
							order_id: v.id,
							refund_reason: ''
						};
						break
					case 'maked':
						n = "你确定制作完成吗";
						a = 'maked';
						url = '/admin/order.Place/updateOrder';
						data = {
							order_id: v.id,
							status: 51
						};
						break;
					case 'completeOrder':
						n = "你确定完成订单吗";
						a = 'complete';
						break;
					case 'completeing':
						n = "你确定确认取单吗";
						a = 'complete';
						url = '/admin/order.Place/updateOrder';
						data = {
							order_id: v.id,
							status: 52
						};
						break;
					case 'rejecting':
						n = "你确定拒绝退款吗";
						a = 'reject';
						break;
				}
				console.log(a, n)
				if (a == 'received' || a == 'maked' || a == 'completeOrder') {
					let {
						msg
					} = await this.beg.request({
						url: `${this.api[a]}/${v.id}`,
						method: "POST",
					})
					this.fetchData()
					uni.$u.toast(msg)
				} else {
					//这里需要修改为咱们得格式
					uni.showModal({
						title: '温馨提示',
						content: n,
						success: async (res) => {
							if (res.confirm) {
								let {
									msg
								} = await this.beg.request({
									url: url,
									data: data,
									method: "POST",
								})
								this.fetchData()
								uni.$u.toast(msg)
							}
						}
					});
				}
			},
			async handOp(type, v) {
				this.form = v
				if (type == 'checkout') {
					this.showPay = true
					return
				} else if (type == 'addOrder') {
					return uni.reLaunch({
						url: `/pages/order/orderMeal/index?id=${this.form.table.id}`
					})
				} else if (type == 'call') {
					const {
						msg
					} = await this.beg.request({
						url: `${this.api.call}/${v.takeScreen.id}`,
						method: "POST",
					})
					uni.$u.toast(msg)
					this.fetchData()
					return
				} else if (type == 'refusal') {
					uni.showModal({
						title: '取消订单',
						content: '请谨慎操作，建议提前与客户沟通达成一致！',
						cancelText: '再考虑下',
						confirmText: '确认取消',
						success: async (res) => {
							if (res.confirm) {
								return uni.navigateTo({
									url: `/pages/order/refusal?id=${v.id}&scene=${v.scene}&storeId=${v.storeId}`
								})
							}
						}
					})
					return
				}
				let n = '',
					a = ''
				switch (type) {
					case 'orderPrint':
						n = "你确定打印该订单吗";
						a = 'printOrder';
						break;
					case 'canceling':
						n = "你确定取消订单吗";
						a = 'oClose';
						break;
					case 'refusal':
						n = "你确定拒单吗";
						a = 'inOClose';
						break;
					case 'receiving':
						n = "你确定立即接单吗";
						a = 'inStoreReceived';
						break;
					case 'refunding':
						n = "你确定同意退款吗";
						a = 'inRefund';
						break
					case 'refundOrder':
						n = "你确定退款吗";
						a = 'inRefund';
						break
					case 'maked':
						n = "你确定制作完成吗";
						a = 'inStoreMaked';
						break;
					case 'completeOrder':
						n = "你确定完成订单吗";
						a = 'inStoreComplete';
						break;
					case 'completeing':
						n = "你确定确认取单吗";
						a = 'complete';
						break;
					case 'rejecting':
						n = "你确定拒绝退款吗";
						a = 'reject';
						break;
					case 'cltable':
						n = "你确定清台吗";
						a = 'inStoreComplete';
						break;
				}
				console.log(a, n)
				if (a == 'received' || a == 'maked' || a == 'completeOrder') {
					let {
						msg
					} = await this.beg.request({
						url: `${this.api[a]}/${v.id}`,
						method: "POST",
					})
					this.fetchData()
					uni.$u.toast(msg)
				} else if (a == 'cltable') {
					let {
						msg
					} = await this.beg.request({
						url: `${this.api[a]}/${v.id}`,
						method: "POST",
						data: {
							scene: v.scene
						}
					})
					this.fetchData()
					uni.$u.toast(msg)
				} else {
					uni.showModal({
						title: '温馨提示',
						content: n,
						success: async (res) => {
							if (res.confirm) {
								let {
									msg
								} = await this.beg.request({
									url: `${this.api[a]}/${v.id}`,
									method: "POST",
								})
								this.fetchData()
								uni.$u.toast(msg)
							}
						}
					});
				}
			},
			searchChange(e){
				this.newParams.page = 1
				this.newParams.product_name = ''
				this.newParams.order_status = 0
				this.newParams.status = 0
				this.newOrder()
			},
			async payOp(type, v) {
				this.form = v
				if (type == 'orderPrint') {
					const {
						msg
					} = await this.beg.request({
						url: `${this.api.printOrder}/${v.id}`,
						data: {
							scene: 4
						},
						method: "POST",
					})
					uni.$u.toast(msg)
					this.fetchData()
					return
				}
				let n = '',
					a = ''
				switch (type) {
					case 'refundOrder':
						n = "你确定退款吗";
						a = 'ppRefund';
						break
				}
				console.log(a, n)
				uni.showModal({
					title: '温馨提示',
					content: n,
					success: async (res) => {
						if (res.confirm) {
							let {
								msg
							} = await this.beg.request({
								url: `${this.api[a]}/${v.orderSn}`,
								method: "POST",
							})
							this.fetchData()
							uni.$u.toast(msg)
						}
					}
				});
			},
			async jfop(type, v) {
				this.form = v
				if (type == 'orderPrint') {
					const {
						msg
					} = await this.beg.request({
						url: `${this.api.printOrder}/${v.id}`,
						data: {
							scene: 6
						},
						method: "POST",
					})
					uni.$u.toast(msg)
					this.fetchData()
					return
				}
				if (type == 'comDelivery') {
					var that = this
					uni.scanCode({
						onlyFromCamera: true,
						success: function(res) {
							if (res.result) {
								that.hexiao(res.result, v)
							}
						}
					});
					return
				}
				let n = '',
					a = ''
				switch (type) {
					case 'refund':
						n = "你确定同意退款吗";
						a = 'pointRefund';
						break
					case 'rejectRefund':
						n = "你确定拒绝退款吗";
						a = 'pointRejectRefund';
						break
				}
				console.log(a, n)
				uni.showModal({
					title: '温馨提示',
					content: n,
					success: async (res) => {
						if (res.confirm) {
							let {
								msg
							} = await this.beg.request({
								url: `${this.api[a]}/${v.orderSn}`,
								method: "POST",
							})
							this.fetchData()
							uni.$u.toast(msg)
						}
					}
				});
			},
			async hexiao(i, v) {
				let {
					data,
					msg,
				} = await this.beg.request({
					url: `${this.api.pointVerification}/${v.orderSn}`,
					method: 'POST',
					data: {
						code: i
					}
				})
				uni.$u.toast(msg)
				this.fetchData()
			},
			async svOp(type, v) {
				this.form = v
				if (type == 'orderPrint') {
					const {
						msg
					} = await this.beg.request({
						url: `${this.api.printOrder}/${v.id}`,
						data: {
							scene: 5
						},
						method: "POST",
					})
					uni.$u.toast(msg)
					this.fetchData()
					return
				}
			},
			async newOp(type, v) {
				console.log(type, v)
				// this.form = v
				// if (type == 'orderPrint') {
				// 	const {
				// 		msg
				// 	} = await this.beg.request({
				// 		url: `${this.api.printOrder}/${v.id}`,
				// 		data: {
				// 			scene: 5
				// 		},
				// 		method: "POST",
				// 	})
				// 	uni.$u.toast(msg)
				// 	this.fetchData()
				// 	return
				// }
			},
			async handPrint(v) {
				let {
					msg
				} = await this.beg.request({
					url: `${this.api.printOrder}/${v.id}`,
					method: "POST",
					data: {
						scene: v.scene
					}
				})
				this.fetchData()
				uni.$u.toast(msg)
			},
			async svPrint(v) {
				let {
					msg
				} = await this.beg.request({
					url: `${this.api.printOrder}/${v.id}`,
					method: "POST",
					data: {
						scene: 5
					}
				})
				this.fetchData()
				uni.$u.toast(msg)
			},
			async payPrint(v) {
				let {
					msg
				} = await this.beg.request({
					url: `${this.api.printOrder}/${v.id}`,
					method: "POST",
					data: {
						scene: 4
					}
				})
				this.fetchData()
				uni.$u.toast(msg)
			},
			async open(row) {
				let {
					deliverySetting
				} = uni.getStorageSync('setInfo')
				this.mytName = deliverySetting.appId || "麦芽田聚合配送";
				this.mKName = deliverySetting.appId2 || "码科配送";
				this.wsbName = deliverySetting.wsbName || "外送帮";
				let info = uni.getStorageSync('storeInfo')
				if (info) {
					this.storeInfo = info;
				}
				if (row.deliveryStoreRule.channel.includes(1)) {
					this.psform.channel = 1;
				} else if (row.deliveryStoreRule.channel.includes(2)) {
					this.psform.channel = 2;
				} else if (row.deliveryStoreRule.channel.includes(3)) {
					this.psform.channel = 3;
				} else {
					this.psform.channel = null;
				}
				this.psform.deliveryType = row.deliveryType
				this.fhChannel = row.deliveryStoreRule && row.deliveryStoreRule.channel
				this.rows = row;
				this.fqps = true;
			},
			changeType(val) {
				if (val == 2) {
					this.psform.channel = 0;
				} else {
					if (this.rows.deliveryStoreRule.channel.includes(1)) {
						this.psform.channel = 1;
					} else if (this.rows.deliveryStoreRule.channel.includes(2)) {
						this.psform.channel = 2;
					} else if (this.rows.deliveryStoreRule.channel.includes(3)) {
						this.psform.channel = 3;
					} else {
						this.psform.channel = null;
					}
				}
			},
			async save() {
				if (!this.psform.channel && String(this.psform.channel) !== '0') {
					return uni.$u.toast('请选择配送渠道')
				}
				let {
					msg
				} = await this.beg.request({
					url: `${this.api.delivery}/${this.rows.id}`,
					method: "POST",
					data: this.psform,
				})
				this.fetchData()
				uni.$u.toast(msg)
				this.fqps = false
			},

			maskClick(e) {
				if (this.time) {
					this.queryForm.startTime = this.time.length > 2 ? this.time : this.time[0]
					this.queryForm.endTime = this.time.length > 2 ? this.time : this.time[1]
					this.queryForm.timeType = 1
					this.queryForm.timeChannel = 'created_at'
				}
				this.fetchData()
			},
			finish() {},
			draw() {},
			toDtail(v) {
				uni.navigateTo({
					url: `/pages/order/detail?id=${v.id}`
				})
			},
			onPulling(e) {
				console.log(e)
			},
			// onRefresh() {
			// 	if (this._freshing) return;
			// 	this.triggered = 'restore';
			// 	this._freshing = true;
			// 	this.queryForm.pageNo = 1
			// 	this.fetchData()
			// 	setTimeout(() => {
			// 		this.triggered = false;
			// 		this._freshing = false;
			// 	}, 500)
			// },
			// onRestore() {
			// 	this.triggered = 'restore';
			// },
			// onAbort() {},
			storeNotes(v) {
				this.noteForm = v
				this.notesShow = true
			},
			async notesConfirm() {
				let {
					msg
				} = await this.beg.request({
					url: `${this.api.inNotes}/${this.noteForm.id}`,
					method: "POST",
					data: {
						notes: this.reason
					},
				})
				this.reason = ''
				this.fetchData()
				uni.$u.toast(msg)
				this.notesShow = false
			},
			handTab(i) {
				this.current = i
				if (i == 1) {
					uni.navigateTo({
						url: `/pages/home/afterSale/index`
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.oHome {
		padding-bottom: 130rpx;
		// overflow: auto;
	}

	.tabs {
		padding: 5rpx 0;
		border-radius: 15rpx;

		.line {
			margin-top: 10rpx;
			width: 30rpx;
			height: 8rpx;
			margin-left: 12rpx;
		}
	}

	.right {
		padding-right: 160rpx;
	}

	.tab {
		padding: 15rpx;
		width: 50%;
		color: #666;
	}

	.isTab {
		border-radius: 15rpx;
		font-weight: 600;
		// color: #fff;
	}

	/deep/.u-tabs__wrapper__nav {
		// padding-left: 150px;
		// justify-content: space-around !important;
	}

	.types {
		width: 650px;
		height: 54rpx;

		.type {
			display: inline-block;
			margin-right: 15rpx;
			padding: 10rpx 10rpx;
			height: 50rpx;
			border-radius: 8rpx;
			background: #fff;
		}

		// .isType {
		// 	// color: #49c265;
		// 	// border: 1px solid #49c265;
		// 	background-color: #dcf0e7;
		// }
	}

	.num {
		display: flex;
		flex-direction: column;
		align-items: flex-start;
		justify-content: flex-start;
	}

	.tool {
		padding: 10rpx 18rpx;
		background: #fff6e4;
		color: #e8b040;
		border-radius: 10rpx;
	}

	/deep/.u-button__text {
		font-weight: bold !important;
	}

	/deep/.u-button {
		height: 58rpx !important;
	}

	/deep/.u-button--normal {
		font-size: 24rpx !important;
	}

	/deep/.uni-datetime-picker--btn {
		background-color: #FDDA34;
		color: #000;
		font-weight: bold;
	}

	/deep/.uni-calendar-item--multiple {

		.uni-calendar-item--before-checked {
			background-color: #FDDA34 !important;
		}

		.uni-calendar-item--after-checked {
			background-color: #FDDA34 !important;
		}
	}

	/deep/.uni-calendar-item__weeks-box .uni-calendar-item--checked {
		background-color: #FDDA34 !important;
	}

	/deep/.uni-calendar-item--before-checked .uni-calendar-item--checked-text,
	/deep/.uni-calendar-item--after-checked .uni-calendar-item--checked-text {
		color: #000;
	}

	/deep/.uni-calendar-item--checked .uni-calendar-item--checked-text {
		color: #000;
	}

	/deep/.psbt .u-button {
		height: 70rpx !important;
	}

	/deep/.u-popup {
		flex: 0 !important;
	}

	/deep/.uni-calendar--fixed {
		z-index: 9999;
	}

	.np {
		height: 900rpx;
	}

	.db {
		height: 100%;
		// padding-bottom: 300rpx;
		// height: 1180rpx;
	}

	.psw {
		padding: 30rpx;
		font-size: 28rpx;
		width: 650rpx;
	}

	.bff1 {
		background: #f1f1f1;
	}

	.weixinButton {
		width: 104rpx;
		height: 104rpx;
		border-radius: 50%;
		background: #b6c443e8;
		box-shadow: 0 4rpx 20rpx 0 rgba(0, 0, 0, 0.1);
		position: fixed;
		right: 32rpx;
		bottom: 30vh;
		display: flex;
		justify-content: center;
		flex-direction: column;

		.img {
			width: 52rpx;
			height: 52rpx;
		}

		.text {
			width: 48rpx;
			height: 34rpx;
			font-size: 24rpx;
			font-weight: 500;
			color: rgba(255, 255, 255, 1);
			margin-left: 4rpx;
			display: flex;
			justify-content: center;
			align-items: center;
		}
	}
</style>